package BubbleSort;/*
 *
 * @author 陈粒
 * @version 创建时间：2021/7/1 20:12
 */

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int[] a = new int[]{55, 33, 16, 17, 88, 24};
        int[] newA = method(a);
        System.out.println(Arrays.toString(newA));
    }

    public static int[] method(int[] b) {
        for (int i = 1; i <= b.length - 1; i++)//最多比较数的数量-1次，所以这里是b.length-1
            for (int j = 0; j < b.length - 1; j++) {//从数组下标0开始比较，最后一个数组元素不用比较，所以这里是j < b.length - 1
                if (b[j] > b[j + 1]) {
                    int t = b[j];
                    b[j] = b[j + 1];
                    b[j + 1] = t;
                }
            }
        return b;
    }
}
